package com.seedwill.common.meta.schema;

import java.util.Hashtable;
import java.util.List;
import java.util.Map;

public class SchemaMetaInfo implements java.io.Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1205319400897999247L;
	private String dbType;
	public String getDbType() {
		return dbType;
	}

	public void setDbType(String dbType) {
		this.dbType = dbType;
	}

	private String tableName;
	private String tableCode;
	private String tableRemark;
	
	private List<FieldMetaInfo> colMetaInfos;
	
	private Map<String, FieldMetaInfo> colMetaCaches;
	
	private List<String> tablePrimaryKeys;
	private List<SchemaFieldPair> tableImportedKeys;
	private List<SchemaFieldPair> tableExportedKeys;
	
	public List<String> getTablePrimaryKeys() {
		return tablePrimaryKeys;
	}

	public void setTablePrimaryKeys(List<String> tablePrimaryKeys) {
		this.tablePrimaryKeys = tablePrimaryKeys;
	}

	public List<SchemaFieldPair> getTableImportedKeys() {
		return tableImportedKeys;
	}

	public void setTableImportedKeys(List<SchemaFieldPair> tableImportedKeys) {
		this.tableImportedKeys = tableImportedKeys;
	}

	public List<SchemaFieldPair> getTableExportedKeys() {
		return tableExportedKeys;
	}

	public void setTableExportedKeys(List<SchemaFieldPair> tableExportedKeys) {
		this.tableExportedKeys = tableExportedKeys;
	}

	public FieldMetaInfo getFieldMeta(String colName){
		if(colMetaCaches == null){
			colMetaCaches = new Hashtable<String, FieldMetaInfo>();
		}
		if(!colMetaCaches.containsKey(colName)){
			for(FieldMetaInfo fm : colMetaInfos){
				if(fm.getColCode().equals(colName)){
					colMetaCaches.put(colName, fm);
					break;
				}
			}
		}
		return colMetaCaches.containsKey(colName)?colMetaCaches.get(colName):null;
	}
	
	public String getTableName() {
		return tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
	public String getTableCode() {
		return tableCode;
	}
	public void setTableCode(String tableCode) {
		this.tableCode = tableCode;
	}
	public List<FieldMetaInfo> getColMetaInfos() {
		return colMetaInfos;
	}
	public void setColMetaInfos(List<FieldMetaInfo> colMetaInfos) {
		this.colMetaInfos = colMetaInfos;
	}
	public String getTableRemark() {
		return tableRemark;
	}
	public void setTableRemark(String tableRemark) {
		this.tableRemark = tableRemark;
	}

	public boolean hasField(String column) {
		boolean flag = false;
		if(colMetaInfos!= null && colMetaInfos.size()>0){
			for(FieldMetaInfo fmi : colMetaInfos){
				if(fmi!=null && fmi.getColCode().equals(column)){
					flag = true;
					break;
				}
			}
		}
		return flag;
	}

	public String getColRemark(String column) {
		String flag = null;
		if(colMetaInfos!= null && colMetaInfos.size()>0){
			for(FieldMetaInfo fmi : colMetaInfos){
				if(fmi!=null && fmi.getColCode().equals(column)){
					flag = fmi.getColRemarks();
					break;
				}
			}
		}
		return flag;
	}
	
	public void setColRemark(String col, String colDesc) {
		if(colMetaInfos!= null && colMetaInfos.size()>0){
			for(FieldMetaInfo fmi : colMetaInfos){
				if(fmi!=null && fmi.getColCode().equals(col)){
					fmi.setColRemarks(colDesc);
					break;
				}
			}
		}
	}
}
